import 'dart:ffi';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:wx_faxian/const.dart';
import "../../components/discover_cell.dart";

class MinePage extends StatefulWidget {
  const MinePage({super.key});

  @override
  State<MinePage> createState() => _MinePageState();
}

class _MinePageState extends State<MinePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 刘海高度设置
      extendBodyBehindAppBar: true,
      body: Container(
        color: primaryColor,
        child: Stack(
          children: [
            ListView(
              children: const [
                // 头部
                HeaderWidget(),
                // list
                BottomWidget()
              ],
            ),
            const Positioned(
              right: 10,
              top: 30,
              child: Icon(
                Icons.camera_alt,
                color: Colors.red,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class HeaderWidget extends StatelessWidget {
  const HeaderWidget({super.key});

  @override
  Widget build(BuildContext context) {
    // 去掉顶部padding ，安卓模拟器不生效。可能仅限ios
    return MediaQuery.removePadding(
      removeTop: true,
      context: context,
      child: Container(
          color: Colors.white,
          margin: const EdgeInsets.only(bottom: 10),
          child: Container(
            margin: const EdgeInsets.all(10),
            child: Flex(
              direction: Axis.horizontal,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const ClipOval(
                  child: Image(
                    image: AssetImage('images/tx.jpg'),
                    width: 70,
                    height: 70,
                    fit: BoxFit.cover,
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    height: 70,
                    margin: const EdgeInsets.only(left: 10),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        const Text(
                          '用户名',
                          style: TextStyle(fontSize: 18),
                        ),
                        Container(
                          margin: const EdgeInsets.only(top: 5),
                          child: const Row(children: [
                            Expanded(
                              flex: 1,
                              child: Text(
                                '微信号2：123456789',
                                style:
                                    TextStyle(fontSize: 12, color: Colors.grey),
                              ),
                            ),
                            Icon(Icons.arrow_forward_ios, size: 15),
                          ]),
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
          )),
    );
  }
}

class BottomWidget extends StatelessWidget {
  const BottomWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        // list
        DiscoverCell(
          title: '支付',
          imageName: 'images/zf.png',
        ),
        const SizedBox(height: 10),
        DiscoverCell(
          title: '收藏',
          imageName: 'images/sc.png',
        ),
        Row(
          children: [
            Container(width: 50, height: 0.5, color: Colors.white),
            Container(height: 0.5),
          ],
        ),
        DiscoverCell(
          title: '相册',
          imageName: 'images/xc.png',
        ),
        Row(
          children: [
            Container(width: 50, height: 0.5, color: Colors.white),
            Container(height: 0.5),
          ],
        ),
        DiscoverCell(
          title: '卡包',
          imageName: 'images/kb.png',
        ),
        Row(
          children: [
            Container(width: 50, height: 0.5, color: Colors.white),
            Container(height: 0.5),
          ],
        ),
        DiscoverCell(
          title: '表情',
          imageName: 'images/bq.png',
        ),
        Row(
          children: [
            Container(width: 50, height: 0.5, color: Colors.white),
            Container(height: 0.5),
          ],
        ),
        const SizedBox(height: 10),
        DiscoverCell(
          title: '设置',
          imageName: 'images/sz.png',
        ),
      ],
    );
  }
}
